﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using WebApiClientCore.Serialization.JsonConverters;
using Yyd.ExternalService.CustomerMarking;

namespace Microsoft.Extensions
{
    public static class ExternalServiceExtensions
    {
        /// <summary>
        /// 
        /// </summary>
        private const string ConfigSectionName = "ExternalService";

        /// <summary>
        /// 添加客户营销外部服务
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static IServiceCollection AddCustomerMarkingExternalService(this IServiceCollection services,
            IConfiguration configuration)
        {
            var configSection = configuration.GetSection($"{ConfigSectionName}:CustomerMarking");

            services.Configure<CustomerMarkingOptions>(configSection);

            services.ConfigureHttpApi<ICustomerExternalService>(configSection)
                .AddHttpApi<ICustomerExternalService>(o =>
                {
                    o.JsonSerializeOptions.Converters.Add(new JsonLocalDateTimeConverter("yyyy-MM-dd HH:mm:ss"));
                });

            return services;
        }
    }
}
